﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using VideoClassLibrary;
using VideoClassLibrary.Model;
using VideoClassLibrary.BusinessLogicLayer;
public partial class TeacherList : AdminUserBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
          
        }

    }
    public void Bind()
    {
        DataSet list = new DataSet();
        TeacherModule ta = new TeacherModule();
        if (this.SchoolID == 0)
        {
            list = ta.GetTeacherListByWhere("order by create_time desc");
        Repeater1.DataSource = getPage(list);
        Repeater1.DataBind();
        }
        else
        {
            DataSet ds = ta.GetTeacherListByWhere(" and SchoolID=" + this.SchoolID + " order by create_time desc");
         Repeater1.DataSource = getPage(ds);
         Repeater1.DataBind();
        }
       
 
    }
    protected void Seacher_Click(object sender, EventArgs e)
    {
        string name = TxtCheckName.Text.Trim();
        string strwhere = "";
        if (name != null && name != "")
        {
            if (this.SchoolID == 0)
            {
                strwhere = " and VT_realname like '%" + name + "%' ";
            }
            else
            {
                strwhere = " and SchoolID=" + this.SchoolID + " and VT_realname like '%" + name + "%' ";
            }
             CheckBind(strwhere);
        }
        else
        {
            Bind();
        }

    }
    public void CheckBind(string strwhere)
    {
        DataSet list = new DataSet();
        TeacherModule ta = new TeacherModule();
        DataSet ds = ta.GetTeacherListByWhere(strwhere);
        Repeater1.DataSource = getPage(ds);
        Repeater1.DataBind();
    }
    public string GetSchNameByID(int schid)
    {
        TeacherModule ta = new TeacherModule();
        string name = ta.GetSchNameByID(schid);
        return name;
    }
    public PagedDataSource getPage(DataSet ds)
    {
        this.pager.RecordCount = ds.Tables[0].Rows.Count;
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = ds.Tables[0].DefaultView;
        pds.AllowPaging = true;
        pds.CurrentPageIndex = pager.CurrentPageIndex - 1;
        pds.PageSize = pager.PageSize;
        return pds;
    }
    protected void pager_PageChanged(object sender, EventArgs e)
    {
         string name = TxtCheckName.Text.Trim();
         if (name != null && name != "")
         { Seacher_Click(sender,e); }
         else { Bind(); }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Addteacher.aspx");
    }
    public void btnUpdate_Click(object sender, CommandEventArgs e)
    {
        Response.Redirect("UpdateTeacher.aspx?TID=" + e.CommandArgument.ToString());
    }
    /// <summary>
    /// 根据选择删除数据
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDelete_Command(object sender, CommandEventArgs e)
    {
        int id = int.Parse(e.CommandArgument.ToString());
        TeacherModule tm = new TeacherModule();
        tm.DeleteTeacher(id);
        Response.Redirect("SearchAndDelTeacher.aspx");
    }
}
